<?php
	/**
	 * This is a MetaControl class, providing a QForm or QPanel access to event handlers
	 * and QControls to perform the Create, Edit, and Delete functionality
	 * of the TableAdmin class.  This code-generated class
	 * contains all the basic elements to help a QPanel or QForm display an HTML form that can
	 * manipulate a single TableAdmin object.
	 *
	 * To take advantage of some (or all) of these control objects, you
	 * must create a new QForm or QPanel which instantiates a TableAdminMetaControl
	 * class.
	 *
	 * Any and all changes to this file will be overwritten with any subsequent
	 * code re-generation.
	 * 
	 * @package My Application
	 * @subpackage MetaControls
	 * property-read TableAdmin $TableAdmin the actual TableAdmin data class being edited
	 * property QLabel $IdControl
	 * property-read QLabel $IdLabel
	 * property QTextBox $UserNameControl
	 * property-read QLabel $UserNameLabel
	 * property QTextBox $PasswordControl
	 * property-read QLabel $PasswordLabel
	 * property QTextBox $LoginIpControl
	 * property-read QLabel $LoginIpLabel
	 * property QDateTimePicker $LoginDateControl
	 * property-read QLabel $LoginDateLabel
	 * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
	 * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
	 */

	class TableAdminMetaControlGen extends QBaseClass {
		// General Variables
		protected $objTableAdmin;
		protected $objParentObject;
		protected $strTitleVerb;
		protected $blnEditMode;

		// Controls that allow the editing of TableAdmin's individual data fields
		protected $lblId;
		protected $txtUserName;
		protected $txtPassword;
		protected $txtLoginIp;
		protected $calLoginDate;

		// Controls that allow the viewing of TableAdmin's individual data fields
		protected $lblUserName;
		protected $lblPassword;
		protected $lblLoginIp;
		protected $lblLoginDate;

		// QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References

		// QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References


		/**
		 * Main constructor.  Constructor OR static create methods are designed to be called in either
		 * a parent QPanel or the main QForm when wanting to create a
		 * TableAdminMetaControl to edit a single TableAdmin object within the
		 * QPanel or QForm.
		 *
		 * This constructor takes in a single TableAdmin object, while any of the static
		 * create methods below can be used to construct based off of individual PK ID(s).
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this TableAdminMetaControl
		 * @param TableAdmin $objTableAdmin new or existing TableAdmin object
		 */
		 public function __construct($objParentObject, TableAdmin $objTableAdmin) {
			// Setup Parent Object (e.g. QForm or QPanel which will be using this TableAdminMetaControl)
			$this->objParentObject = $objParentObject;

			// Setup linked TableAdmin object
			$this->objTableAdmin = $objTableAdmin;

			// Figure out if we're Editing or Creating New
			if ($this->objTableAdmin->__Restored) {
				$this->strTitleVerb = QApplication::Translate('Edit');
				$this->blnEditMode = true;
			} else {
				$this->strTitleVerb = QApplication::Translate('Create');
				$this->blnEditMode = false;
			}
		 }

		/**
		 * Static Helper Method to Create using PK arguments
		 * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
		 * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
		 * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
		 * edit, or if we are also allowed to create a new one, etc.
		 * 
		 * @param mixed $objParentObject QForm or QPanel which will be using this TableAdminMetaControl
		 * @param integer $intId primary key value
		 * @param QMetaControlCreateType $intCreateType rules governing TableAdmin object creation - defaults to CreateOrEdit
 		 * @return TableAdminMetaControl
		 */
		public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			// Attempt to Load from PK Arguments
			if (strlen($intId)) {
				$objTableAdmin = TableAdmin::Load($intId);

				// TableAdmin was found -- return it!
				if ($objTableAdmin)
					return new TableAdminMetaControl($objParentObject, $objTableAdmin);

				// If CreateOnRecordNotFound not specified, throw an exception
				else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
					throw new QCallerException('Could not find a TableAdmin object with PK arguments: ' . $intId);

			// If EditOnly is specified, throw an exception
			} else if ($intCreateType == QMetaControlCreateType::EditOnly)
				throw new QCallerException('No PK arguments specified');

			// If we are here, then we need to create a new record
			return new TableAdminMetaControl($objParentObject, new TableAdmin());
		}

		/**
		 * Static Helper Method to Create using PathInfo arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this TableAdminMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing TableAdmin object creation - defaults to CreateOrEdit
		 * @return TableAdminMetaControl
		 */
		public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::PathInfo(0);
			return TableAdminMetaControl::Create($objParentObject, $intId, $intCreateType);
		}

		/**
		 * Static Helper Method to Create using QueryString arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this TableAdminMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing TableAdmin object creation - defaults to CreateOrEdit
		 * @return TableAdminMetaControl
		 */
		public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::QueryString('intId');
			return TableAdminMetaControl::Create($objParentObject, $intId, $intCreateType);
		}



		///////////////////////////////////////////////
		// PUBLIC CREATE and REFRESH METHODS
		///////////////////////////////////////////////

		/**
		 * Create and setup QLabel lblId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblId_Create($strControlId = null) {
			$this->lblId = new QLabel($this->objParentObject, $strControlId);
			$this->lblId->Name = QApplication::Translate('Id');
			if ($this->blnEditMode)
				$this->lblId->Text = $this->objTableAdmin->Id;
			else
				$this->lblId->Text = 'N/A';
			return $this->lblId;
		}

		/**
		 * Create and setup QTextBox txtUserName
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtUserName_Create($strControlId = null) {
			$this->txtUserName = new QTextBox($this->objParentObject, $strControlId);
			$this->txtUserName->Name = QApplication::Translate('User Name');
			$this->txtUserName->Text = $this->objTableAdmin->UserName;
			$this->txtUserName->Required = true;
			$this->txtUserName->MaxLength = TableAdmin::UserNameMaxLength;
			return $this->txtUserName;
		}

		/**
		 * Create and setup QLabel lblUserName
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblUserName_Create($strControlId = null) {
			$this->lblUserName = new QLabel($this->objParentObject, $strControlId);
			$this->lblUserName->Name = QApplication::Translate('User Name');
			$this->lblUserName->Text = $this->objTableAdmin->UserName;
			$this->lblUserName->Required = true;
			return $this->lblUserName;
		}

		/**
		 * Create and setup QTextBox txtPassword
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtPassword_Create($strControlId = null) {
			$this->txtPassword = new QTextBox($this->objParentObject, $strControlId);
			$this->txtPassword->Name = QApplication::Translate('Password');
			$this->txtPassword->Text = $this->objTableAdmin->Password;
			$this->txtPassword->Required = true;
			$this->txtPassword->MaxLength = TableAdmin::PasswordMaxLength;
			return $this->txtPassword;
		}

		/**
		 * Create and setup QLabel lblPassword
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblPassword_Create($strControlId = null) {
			$this->lblPassword = new QLabel($this->objParentObject, $strControlId);
			$this->lblPassword->Name = QApplication::Translate('Password');
			$this->lblPassword->Text = $this->objTableAdmin->Password;
			$this->lblPassword->Required = true;
			return $this->lblPassword;
		}

		/**
		 * Create and setup QTextBox txtLoginIp
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtLoginIp_Create($strControlId = null) {
			$this->txtLoginIp = new QTextBox($this->objParentObject, $strControlId);
			$this->txtLoginIp->Name = QApplication::Translate('Login Ip');
			$this->txtLoginIp->Text = $this->objTableAdmin->LoginIp;
			$this->txtLoginIp->MaxLength = TableAdmin::LoginIpMaxLength;
			return $this->txtLoginIp;
		}

		/**
		 * Create and setup QLabel lblLoginIp
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblLoginIp_Create($strControlId = null) {
			$this->lblLoginIp = new QLabel($this->objParentObject, $strControlId);
			$this->lblLoginIp->Name = QApplication::Translate('Login Ip');
			$this->lblLoginIp->Text = $this->objTableAdmin->LoginIp;
			return $this->lblLoginIp;
		}

		/**
		 * Create and setup QDateTimePicker calLoginDate
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calLoginDate_Create($strControlId = null) {
			$this->calLoginDate = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calLoginDate->Name = QApplication::Translate('Login Date');
			$this->calLoginDate->DateTime = $this->objTableAdmin->LoginDate;
			$this->calLoginDate->DateTimePickerType = QDateTimePickerType::DateTime;
			return $this->calLoginDate;
		}

		/**
		 * Create and setup QLabel lblLoginDate
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblLoginDate_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblLoginDate = new QLabel($this->objParentObject, $strControlId);
			$this->lblLoginDate->Name = QApplication::Translate('Login Date');
			$this->strLoginDateDateTimeFormat = $strDateTimeFormat;
			$this->lblLoginDate->Text = sprintf($this->objTableAdmin->LoginDate) ? $this->objTableAdmin->LoginDate->__toString($this->strLoginDateDateTimeFormat) : null;
			return $this->lblLoginDate;
		}

		protected $strLoginDateDateTimeFormat;




		/**
		 * Refresh this MetaControl with Data from the local TableAdmin object.
		 * @param boolean $blnReload reload TableAdmin from the database
		 * @return void
		 */
		public function Refresh($blnReload = false) {
			if ($blnReload)
				$this->objTableAdmin->Reload();

			if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objTableAdmin->Id;

			if ($this->txtUserName) $this->txtUserName->Text = $this->objTableAdmin->UserName;
			if ($this->lblUserName) $this->lblUserName->Text = $this->objTableAdmin->UserName;

			if ($this->txtPassword) $this->txtPassword->Text = $this->objTableAdmin->Password;
			if ($this->lblPassword) $this->lblPassword->Text = $this->objTableAdmin->Password;

			if ($this->txtLoginIp) $this->txtLoginIp->Text = $this->objTableAdmin->LoginIp;
			if ($this->lblLoginIp) $this->lblLoginIp->Text = $this->objTableAdmin->LoginIp;

			if ($this->calLoginDate) $this->calLoginDate->DateTime = $this->objTableAdmin->LoginDate;
			if ($this->lblLoginDate) $this->lblLoginDate->Text = sprintf($this->objTableAdmin->LoginDate) ? $this->objTableAdmin->LoginDate->__toString($this->strLoginDateDateTimeFormat) : null;

		}



		///////////////////////////////////////////////
		// PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
		///////////////////////////////////////////////





		///////////////////////////////////////////////
		// PUBLIC TABLEADMIN OBJECT MANIPULATORS
		///////////////////////////////////////////////

		/**
		 * This will save this object's TableAdmin instance,
		 * updating only the fields which have had a control created for it.
		 */
		public function SaveTableAdmin() {
			try {
				// Update any fields for controls that have been created
				if ($this->txtUserName) $this->objTableAdmin->UserName = $this->txtUserName->Text;
				if ($this->txtPassword) $this->objTableAdmin->Password = $this->txtPassword->Text;
				if ($this->txtLoginIp) $this->objTableAdmin->LoginIp = $this->txtLoginIp->Text;
				if ($this->calLoginDate) $this->objTableAdmin->LoginDate = $this->calLoginDate->DateTime;

				// Update any UniqueReverseReferences (if any) for controls that have been created for it

				// Save the TableAdmin object
				$this->objTableAdmin->Save();

				// Finally, update any ManyToManyReferences (if any)
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * This will DELETE this object's TableAdmin instance from the database.
		 * It will also unassociate itself from any ManyToManyReferences.
		 */
		public function DeleteTableAdmin() {
			$this->objTableAdmin->Delete();
		}		



		///////////////////////////////////////////////
		// PUBLIC GETTERS and SETTERS
		///////////////////////////////////////////////

		/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				// General MetaControlVariables
				case 'TableAdmin': return $this->objTableAdmin;
				case 'TitleVerb': return $this->strTitleVerb;
				case 'EditMode': return $this->blnEditMode;

				// Controls that point to TableAdmin fields -- will be created dynamically if not yet created
				case 'IdControl':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'IdLabel':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'UserNameControl':
					if (!$this->txtUserName) return $this->txtUserName_Create();
					return $this->txtUserName;
				case 'UserNameLabel':
					if (!$this->lblUserName) return $this->lblUserName_Create();
					return $this->lblUserName;
				case 'PasswordControl':
					if (!$this->txtPassword) return $this->txtPassword_Create();
					return $this->txtPassword;
				case 'PasswordLabel':
					if (!$this->lblPassword) return $this->lblPassword_Create();
					return $this->lblPassword;
				case 'LoginIpControl':
					if (!$this->txtLoginIp) return $this->txtLoginIp_Create();
					return $this->txtLoginIp;
				case 'LoginIpLabel':
					if (!$this->lblLoginIp) return $this->lblLoginIp_Create();
					return $this->lblLoginIp;
				case 'LoginDateControl':
					if (!$this->calLoginDate) return $this->calLoginDate_Create();
					return $this->calLoginDate;
				case 'LoginDateLabel':
					if (!$this->lblLoginDate) return $this->lblLoginDate_Create();
					return $this->lblLoginDate;
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			try {
				switch ($strName) {
					// Controls that point to TableAdmin fields
					case 'IdControl':
						return ($this->lblId = QType::Cast($mixValue, 'QControl'));
					case 'UserNameControl':
						return ($this->txtUserName = QType::Cast($mixValue, 'QControl'));
					case 'PasswordControl':
						return ($this->txtPassword = QType::Cast($mixValue, 'QControl'));
					case 'LoginIpControl':
						return ($this->txtLoginIp = QType::Cast($mixValue, 'QControl'));
					case 'LoginDateControl':
						return ($this->calLoginDate = QType::Cast($mixValue, 'QControl'));
					default:
						return parent::__set($strName, $mixValue);
				}
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
	}
?>